package com.po.web;

import com.po.scrapy.spiders.RedWebProcessor;
import com.po.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.pipeline.ConsolePipeline;

/**
 * @author zxw
 * @date 2020/7/28 21:08
 */
@RestController
@EnableScheduling
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @GetMapping("/getRedWeb")
    public void test() {
        Spider.create(new RedWebProcessor(articleService))
                .thread(10)
                .addUrl("http://www.rednet.cn/")
                .addPipeline(new ConsolePipeline()).run();
    }
}
